/****************************************************************************
 *
 * Copyright (C) 2003-2008 Los Alamos National Security, LLC
 *                         Packet Analytics Corporation
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License Version 2 as
 * published by the Free Software Foundation.  You may not use, modify or
 * distribute this program under any other version of the GNU General
 * Public License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 ****************************************************************************/
package nfse.query;

import java.io.*;

/**
 * @author bduphoff
 * 
 * TODO To change the template for this generated type comment go to Window -
 * Preferences - Java - Code Style - Code Templates
 */
public class IndexInfo {

	public int keyLength = -1;

	public int pageSize = -1;

	public int month = -1;

	public int day = -1;

	public int year = -1;

	public int run = -1;

	public int type = -1;

	public int file = -1;

	public int field = -1;

	public String sessionFile = "";

	public String delimiter = "";
	
	public String indexPath = "";

	public static IndexInfo processInfo(String path) {
		try {
			IndexInfo info = new IndexInfo();
			info.delimiter = "";
			info.keyLength = -1;
			info.indexPath = path;
			LineNumberReader in = new LineNumberReader(new FileReader(path + "/info"));
			String line = in.readLine();
			while (line != null) {
				String[] tokens = line.split(" ");
				if (tokens.length == 2) {
					//System.out.println("INFO: " + line);
					if (tokens[0].equals("dataFile")) {
						info.sessionFile = tokens[1];
					} else if (tokens[0].equals("keyLength")) {
						info.keyLength = Integer.parseInt(tokens[1]);
					} else if (tokens[0].equals("delimiter")) {
						info.delimiter = tokens[1];
					} else if (tokens[0].equals("pageSize")) {
						info.pageSize = Integer.parseInt(tokens[1]);
					} else if (tokens[0].equals("month")) {
						info.month = Integer.parseInt(tokens[1]);
					} else if (tokens[0].equals("day")) {
						info.day = Integer.parseInt(tokens[1]);
					} else if (tokens[0].equals("year")) {
						info.year = Integer.parseInt(tokens[1]);
					} else if (tokens[0].equals("run")) {
						info.run = Integer.parseInt(tokens[1]);
					} else if (tokens[0].equals("type")) {
						info.type = Integer.parseInt(tokens[1]);
					} else if (tokens[0].equals("file")) {
						info.file = Integer.parseInt(tokens[1]);
					} else if (tokens[0].equals("field")) {
						info.field = Integer.parseInt(tokens[1]);
					}
				}
				line = in.readLine();
			}
			in.close();
			return info;
		} catch (Exception E) {
			E.printStackTrace();
		}
		return null;
	}

}